package com.sinopec.basemodule.utils;

import android.util.Base64;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * URLEncode+Base64 加密
 * String url = "http://example.com/search?query=Android+Development";
 * String encodedURL = EncodingUtils.encodeURL(url); // 进行URL编码
 * String base64Encoded = EncodingUtils.encodeBase64("Hello, World!"); // 进行Base64编码
 * String decoded = EncodingUtils.decodeBase64(base64Encoded); // 进行Base64解码
 */
public class EncodingUtils {
    public static String encodeURL(String url) {
        try {
            return URLEncoder.encode(url, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null; // 或者可以选择抛出异常
        }
    }

    public static String encodeBase64(String input) {
        return Base64.encodeToString(input.getBytes(), Base64.DEFAULT);
    }

    public static String decodeBase64(String input) {
        byte[] decodedBytes = Base64.decode(input, Base64.DEFAULT);
        return new String(decodedBytes);
    }


}